﻿using Furion.Schedule;
using Minio;
using System.Reflection;

namespace Project1.Application
{
    /// <summary>
    /// 系统服务接口
    /// </summary>
    public class SystemAppService : IDynamicApiController
    {
        private readonly ISystemService _systemService;
        private readonly ISchedulerFactory _schedulerFactory;
        public SystemAppService(ISystemService systemService,
        ISchedulerFactory schedulerFactory)
        {
            _systemService = systemService;
            _schedulerFactory = schedulerFactory;
        }

        /// <summary>
        /// 获取系统描述
        /// </summary>
        /// <returns></returns>
        public string GetDescription()
        {
            var trigger = new
            {
                JobId = "job_log",
                TriggerType = "Furion.Schedule.PeriodTrigger",
                AssemblyName = "Furion.Pure",
                Args = "[5000]",
                Description="11",
                NumberOfRuns=10,
                MaxNumberOfRuns=0,
                NumberOfErrors=2,
                NumRetries=1,
                RetryTimeout=1000,
                StartNow=true,
                RunOnStart=true,
                TriggerId="test_1",
            };

            var triggerBuilder =TriggerBuilder.Create(trigger.TriggerId).LoadFrom(trigger).Appended();

            _ = _schedulerFactory.TryGetJob(trigger.JobId, out var _scheduler);
            var b = _scheduler.GetTriggers();
            Console.WriteLine($"触发器个数{b.Count()}");
            _scheduler?.AddTrigger(triggerBuilder);


            _ = _schedulerFactory.TryGetJob(trigger.JobId, out var _scheduler1);
            var a=_scheduler1.GetTriggers();
            Console.WriteLine($"触发器个数{a.Count()}");
            return _systemService.GetDescription();
        }
    }
}